//
// Created by xili on 2024/10/8 18:15.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int sumNumbers(TreeNode *root, int x = 0) {
        if (root == nullptr) {
            return 0;
        }
        x = x * 10 + root->val;
        if (root->left == root->right) { // root 是叶子节点
            return x;
        }
        return sumNumbers(root->left, x) + sumNumbers(root->right, x);
    }
};